package com.bzsg.rightsManagementSystem.service.impl

import com.bzsg.rightsManagementSystem.dao.PermissionDao
import com.bzsg.rightsManagementSystem.dao.PermissionPathRelationDao
import com.bzsg.rightsManagementSystem.pojo.Permission
import com.bzsg.rightsManagementSystem.service.PermissionService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service


@Service
class PermissionServiceImpl : PermissionService {
    @Autowired
    private lateinit var permissionDao: PermissionDao

    @Autowired
    private lateinit var permissionPathRelationDao: PermissionPathRelationDao
    override fun queryById(id: Int): Permission? {
        return permissionDao.queryById(id)
    }

    override fun queryAll(): List<Permission>? {
        return permissionDao.queryAll()
    }

    override fun queryAllByLimit(offset: Int, limit: Int): List<Permission>? {
        val start = (offset - 1) * limit
        return permissionDao.queryAllByLimit(start, limit)
    }

    override fun insert(permission: Permission) {
        permissionDao.insert(permission)
    }

    override fun update(permission: Permission) {
        permissionDao.update(permission)
    }

    override fun deleteById(id: Int) {
        permissionDao.deleteById(id)
    }

    override fun selectListByUser(userId: Int): List<Permission>? {
        return permissionDao.selectListByUser(userId)
    }

    override fun selectListByPath(path: String): List<Permission>? {
        return permissionDao.selectListByPath(path)
    }

    override fun selectTotalPermission(): Int {
        return permissionDao.selectTotalPermissions()
    }

    override fun deleteAllPermissionPathRelationByPermissionId(permissionId: Int) {
        permissionPathRelationDao.deleteAllPermissionPathRelationByPermissionId(permissionId)
    }

    override fun addPermissionPathRelation(permissionId: Int, requestPathId: Int) {
        permissionPathRelationDao.addPermissionPathRelation(permissionId, requestPathId)
    }

    override fun selectPermissionsByRoleId(roleId: Int): List<Permission>? {
        return permissionDao.selectPermissionsByRoleId(roleId)
    }
}